package com.jd.finance.core.controller.api;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jd.finance.core.service.*;
import com.jd.finance.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "首页")
@Slf4j
@RestController
@RequestMapping("/api/core/index")
public class IndexController {

    @Resource
    private ProductService productService;

    @Autowired
    private LoanService loanService;

    @Autowired
    private BankService bankService;

    @Autowired
    private UserService userService;

    @Autowired
    private NoticeService noticeService;

    @Autowired
    private PhotoService photoService;

   @ApiOperation("定位查询")
   @GetMapping("/getLoanListByCity")
   public BaseResult getLoanListByCity(String City){
       if(StringUtils.isBlank(City)){
           log.error("地址信息为空！");
           return BaseResult.error().message("地址信息为空");
       }

       BaseResult baseResult = productService.getLoanListByCity(City);
       return baseResult;
   }

    /**
     * 查询交易人数
     * @return
     */
    @ApiOperation("查询交易人数")
    @GetMapping("/getTradeUserCount")
    public BaseResult getTradeUserCount() {
        return loanService.getTradeUserCount();
    }

    /**
     * 查询累计注册数量
     */
    @ApiOperation("查询累计注册数量")
    @GetMapping("/getUserCount")
    public BaseResult getUserCount() {
        return userService.getUserCount();
    }

    /**
     * 查询平台交易银行的数量
     */
    @ApiOperation("查询平台交易银行的数量")
    @GetMapping("/getBankCount")
    public BaseResult getBankCount() {
        return bankService.getBankCount();
    }

    /**
     * 查询最新一条公告
     */
    @ApiOperation("查询最新一条公告")
    @GetMapping("/getNewAnnounceTop")
    public BaseResult getNewAnnounceTop() {
        return noticeService.getNewAnnounceTop();
    }

    /**
     * 查询最新的六条公告
     */
    @ApiOperation("查询最新的六条公告")
    @GetMapping("/getNewSixAnnounce")
    public BaseResult getNewSixAnnounce() {
        return noticeService.getNewSixAnnounce();
    }

    /**
     * 查询关于我们
     */
    @ApiOperation("查询关于我们")
    @GetMapping("/getAboutWe")
    public BaseResult getAboutWe() {
        return noticeService.getAboutWe();
    }

    /**
     * 查询轮播图图片
     */
    @ApiOperation("查询轮播图图片")
    @GetMapping("/getBanner")
    public BaseResult getBanner() {
        return photoService.getBanner();
    }

    /**
     *查询广告位图片
     */
    @ApiOperation("查询广告位图片")
    @GetMapping("/getAdvertisePhoto")
    public BaseResult getAdvertisePhoto() {
        return photoService.getAdvertisePhoto();

    }
}
